$(document).ready(function(){
	
	
	if($("#utype")){
		var lastel = $("#registerform1");
		$("#utype").bind("change" , function(){
			var val = this.options[this.selectedIndex].value;
			var forshow = $(this.options[this.selectedIndex].getAttribute("forshow"));
			if(lastel!=null){lastel.css("display" , "none");}
			forshow.css("display" , "");
			lastel = forshow;
			
			if(val>1){
				$("#ktype").val(val);
			}
		});
	}

	$.validator.addMethod("atleastone",function(value,element,params){
		if(value==""&&params[0].val()==""&&params[1].val()==""){
			return false;
		}
		return true;
	},"此处手机号、小灵通、固定电话至少选填一项");
	
	$.validator.addMethod("typeselector" , function(value , element , params){
		if(value==""){
			return false;
		}else{
			return true;
		}
	});

	
	if($("#registerform0")){
		$("#registerform0").validate({
			rules: {
				amobile: {
					atleastone : [$("#axlt") , $("#atel")],
					number:true,
					rangelength:[11,11]
				},
				axlt:{
					number:true
				},
				atel:{
					number:true	
				},
				aname: {
					required : true,
					maxlength:5,
					remote:"register_check.php?action=check&type=name"
				},
				apassword: "required",
				re_apassword: {
					required: true,
					equalTo: "#apassword"
				},
				anumber:{
					required : true,
					maxlength : 4,
					remote:"register_check.php?action=check&type=number"
				},
				aemail: {
					email: true
				},
				arequired: "required" 
			},
			messages: {
				amobile:{
					number:"请输入正确的手机号",
					rangelength:"请输入正确的手机号"
				},
				axlt:{
					number:"请输入正确的小灵通号"
				},
				atel:{
					number:"请输入正确的电话号码"
				},
				aname: {
					required : "请输入中介商铺的名称",
					maxlength : "中介名称不要超过五个字",
					remote:"中介名称已存在，请检查"
				},
				apassword: "请输入密码",
				re_apassword: {
					required: "请输入密码",
					equalTo: "两次密码不一致，请检查"
				},
				anumber:{
					required : "请输入中介编号",
					maxlength  : "仅限4位数字，请检查",
					remote: "中介编号已存在，请检查"
				},
				aemail: "请输入正确的邮箱",
				arequired: "请勾选您同意条款方可注册"
			}
		});
	}
	if($("#registerform1")){
		$("#registerform1").validate({
			rules: {
				uname:{
					required : true ,
					remote:"register_check.php?action=check_user&type=name"
				},
				/*umobile: {
					required: true,
					number:true,
					rangelength:[11,11]
				},*/
				upassword: "required",
				re_upassword: {
					required: true,
					equalTo: "#upassword"
				},
				uemail: {
					email: true
				},
				urequired: "required"
			},
			messages: {
				uname: {
					required: "请输入用户名",
					remote:"用户名已存在，请检查"
				},
				/*umobile:{
					required:"请输入您的手机号",
					number:"请输入正确的手机号",
					rangelength:"请输入正确的手机号"
				},*/
				upassword: "请输入密码",
				re_upassword: {
					required:"请输入密码",
					equalTo:"两次密码不一致，请检查"
				},
				uemail: "请输入正确的邮箱",
				urequired: "请勾选您同意条款方可注册"
			}
		});
	}

	if($("#registerform2")){
		$("#registerform2").validate({
			rules: {
				kmobile: {
					atleastone : [$("#kxlt") , $("#ktel")],
					number:true,
					rangelength:[11,11]
				},
				kxlt:{
					number:true
				},
				ktel:{
					number:true	
				},
				kname: {
					required : true,
					maxlength:5,
					remote:{
						url : "register_check.php",
						data : {
							action: "check_kuser",
							ktype: function() { return $("#ktype").val(); },
							type:"name",
							kname:function() { return $("#kname").val(); }
						}
					}
				},
				kpassword: "required",
				re_kpassword: {
					required: true,
					equalTo: "#kpassword"
				},
				kemail: {
					email: true
				},
				krequired: "required" 
			},
			messages: {
				kmobile:{
					number:"请输入正确的手机号",
					rangelength:"请输入正确的手机号"
				},
				kxlt:{
					number:"请输入正确的小灵通号"
				},
				ktel:{
					number:"请输入正确的电话号码"
				},
				kname: {
					required : "请输入中介商铺的名称",
					maxlength : "中介名称不要超过五个字",
					remote:"中介名称已存在，请检查"
				},
				kpassword: "请输入密码",
				re_kpassword: {
					required: "请输入密码",
					equalTo: "两次密码不一致，请检查"
				},
				kemail: "请输入正确的邮箱",
				krequired: "请勾选您同意条款方可注册"
			}
		});
	}
	
	if($("#registerform_pwd")){
		$("#registerform_pwd").validate({
			rules: {
				opassword:{
					required : true ,
					remote:"register_check.php?action=check_pwd&type=pwd"
				},
				npassword: "required",
				re_npassword: {
					required: true,
					equalTo: "#npassword"
				}
			},
			messages: {
				opassword: {
					required: "请输入旧密码",
					remote:"旧密码有误，请检查"
				},
				npassword: "请输入新密码",
				re_npassword: {
					required:"请输入密码",
					equalTo:"两次密码不一致，请检查"
				}
			}
		});
	}

	if($("#registerform3_pwd")){
		$("#registerform3_pwd").validate({
			rules: {
				opassword:{
					required : true ,
					remote:"register_check.php?action=check_kuserpwd&type=pwd"
				},
				npassword: "required",
				re_npassword: {
					required: true,
					equalTo: "#npassword"
				}
			},
			messages: {
				opassword: {
					required: "请输入旧密码",
					remote:"旧密码有误，请检查"
				},
				npassword: "请输入新密码",
				re_npassword: {
					required:"请输入密码",
					equalTo:"两次密码不一致，请检查"
				}
			}
		});
	}
	
	if($("#registerform_edit")){
		$("#registerform_edit").validate({
			rules: {
				amobile: {
					atleastone : [$("#axlt") , $("#atel")],
					number:true,
					rangelength:[11,11]
				},
				axlt:{
					number:true
				},
				atel:{
					number:true	
				},
				aname: {
					required : true,
					maxlength:5,
					remote:"register_check.php?action=check&type=name"
				},
				apassword: "required",
				re_apassword: {
					required: true,
					equalTo: "#apassword"
				},
				anumber:{
					required : true,
					maxlength : 4,
					remote:"register_check.php?action=check&type=number"
				},
				aemail: {
					/*required: true,*/
					email: true
				},
				arequired: "required" 
			},
			messages: {
				amobile:{
					number:"请输入正确的手机号",
					rangelength:"请输入正确的手机号"
				},
				axlt:{
					number:"请输入正确的小灵通号"
				},
				atel:{
					number:"请输入正确的电话号码"
				},
				aname: {
					required : "请输入中介商铺的名称",
					maxlength : "中介名称不要超过五个字",
					remote:"中介名称已存在，请检查"
				},
				apassword: "请输入密码",
				re_apassword: {
					required: "请输入密码",
					equalTo: "两次密码不一致，请检查"
				},
				anumber:{
					required : "请输入中介编号",
					maxlength  : "仅限4位数字，请检查",
					remote: "中介编号已存在，请检查"
				},
				aemail: {
					/*required : "请输入邮箱",*/
					email : "请输入正确的邮箱"
				},
				arequired: "请勾选您同意条款方可注册"
			}
		});
	}
	

	if($("#registerform3_edit")){
		$("#registerform3_edit").validate({
			rules: {
				amobile: {
					atleastone : [$("#axlt") , $("#atel")],
					number:true,
					rangelength:[11,11]
				},
				axlt:{
					number:true
				},
				atel:{
					number:true	
				},
				apassword: "required",
				re_apassword: {
					required: true,
					equalTo: "#apassword"
				},
				aemail: {
					required: true,
					email: true
				},
				arequired: "required" 
			},
			messages: {
				amobile:{
					number:"请输入正确的手机号",
					rangelength:"请输入正确的手机号"
				},
				axlt:{
					number:"请输入正确的小灵通号"
				},
				atel:{
					number:"请输入正确的电话号码"
				},
				apassword: "请输入密码",
				re_apassword: {
					required: "请输入密码",
					equalTo: "两次密码不一致，请检查"
				},
				aemail: {
					required : "请输入邮箱",
					email : "请输入正确的邮箱"
				},
				arequired: "请勾选您同意条款方可注册"
			}
		});
	}

	if($("#loginform")){
		$("#loginform").validate({
			rules: {
				l_username:{
					required : true 
				},
				l_password:{
					required : true 
				}
			},
			messages: {
				l_username: {
					required: "请输入用户名"
				},
				l_password: {
					required: "请输入密码"
				}
			}
		});
	}


	if($("#registerform_advice")){
		$("#registerform_advice").validate({
			rules: {
				aemail:{
					required : true,
					email: true
				},
				advice:{
					required : true,
					maxlength:300
				}
			},
			messages: {
				aemail:{
					required : "请输入您的邮箱",
					email: "请输入正确的邮箱"
				},
				advice:{
					required : "请输入您的意见",
					maxlength:"请不要超过300个字"
				}
			}
		});
	}
	
});